package com.example.yuejianapp14.Activity.Model;

import com.example.yuejianapp14.Activity.JavaBean.Video1;
import com.example.yuejianapp14.Activity.Listener.VideoListener;
import com.example.yuejianapp14.Activity.Servics.VideoService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by jason_lin on 2017/10/17.
 */

public class VideoModel {
    private Retrofit retrofit;
    private String BASEURL = "http://10.0.2.2/YueJian/index.php/Api/Video/";
    private String HeadPhotoNameDefault = "user_headphoto.png";

    public VideoModel() {
        retrofit = new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    public void findVideo(String clubid,final VideoListener listener){
        VideoService videoService=retrofit.create(VideoService.class);
        Call<List<Video1>> call=videoService.findVideo(clubid);
        call.enqueue(new Callback<List<Video1>>() {
            @Override
            public void onResponse(Call<List<Video1>> call, Response<List<Video1>> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listener.onResponse(response.body());
                }else
                    listener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<List<Video1>> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }


    public void allVideo(final VideoListener listener){
        VideoService videoService=retrofit.create(VideoService.class);
        Call<List<Video1>> call=videoService.allvideo();
        call.enqueue(new Callback<List<Video1>>() {
            @Override
            public void onResponse(Call<List<Video1>> call, Response<List<Video1>> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listener.onResponse(response.body());
                }else
                    listener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<List<Video1>> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }


}
